package com.ygqh.baby.utils;

import java.util.Date;

public class ExceptionUtil {
	public static String getExceptionMsg(Exception ex) {
		try {
			StringBuilder sb = new StringBuilder();
			sb.append("【异常类型】:" + ex.getClass().getName() + "【" + ex.getMessage() + "】</br>");
			StackTraceElement[] st = ex.getStackTrace();
			for (StackTraceElement stackTraceElement : st) {
				String exclass = stackTraceElement.getClassName();
				String method = stackTraceElement.getMethodName();
				if (exclass.contains("com.ygqh.baby")) {
					sb.append(DateConvertUtils.formatDateTime(new Date()) + ":" + "[类:" + exclass + "]调用" + method + "时在第" + stackTraceElement.getLineNumber()
							+ "行代码处发生异常!");
				}
			}
			return sb.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return e.getMessage();
		}
	};

}
